<template>
  <div>
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="68px" size="mini">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="姓名" prop="staffName">
            <el-input v-model="queryParams.staffName" clearable placeholder="请输入" @keyup.enter.native="handleQuery"/>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="月份" prop="month">
            <el-date-picker v-model="month" placeholder="选择月" type="month">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table :data="list" border>
      <el-table-column align="center" label="月份">
        <template slot-scope="scope">
          <span>{{ scope.row.year + '-' + scope.row.month }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="姓名" prop="staffName"/>
      <el-table-column align="center" label="岗位" prop="projectPostName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_post" :value="scope.row.projectPostName"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="职务" prop="projectDuitsName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_duits" :value="scope.row.projectDuitsName"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="职别" prop="jobName"/>
      <el-table-column align="center" label="银行卡号" prop="bankCard" width="200px;"/>
      <el-table-column align="center" label="出勤天数" prop="attDays"/>
      <el-table-column align="center" label="基本工资" prop="basicSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.basicSalary) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="绩效津贴" prop="basedSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.basedSalary) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="加班工资" prop="overtimeSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.overtimeSalary) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="福利津贴" prop="welfareSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.welfareSalary) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="奖惩金额" prop="awardSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.awardSalary + scope.row.fineSalary) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="保险费用" prop="insuranceSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.insuranceSalary) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="工服费用" prop="clothesSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.clothesSalary) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="工作计划" prop="workSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.workSalary) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="应发薪酬" prop="inSalary">
        <template slot-scope="scope">
          {{ toMoney(scope.row.inSalary) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="实发薪酬" prop="sendSalary">
        <template slot-scope="scope">
          {{ calculateSalary(scope.row) }}
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button v-hasPermi="['cld:CldPayDetails:edit']" size="mini" type="text"
                     @click="handleViewDetails(scope.row)">查看明细
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum" :total="total"
                @pagination="getList"/>


    <el-dialog :close-on-click-modal="false" :destroy-on-close="true" :visible.sync="isViewPayOpen" append-to-body
               title="明细"
               width="90%">
      <calendar v-if="isViewPayOpen" :dateMonth="currRow.year + '-' + currRow.month"
                :form="currRow" :projectId="$route.params.projectId"></calendar>
    </el-dialog>
  </div>
</template>

<script>
import {getCumulativeSalaryByProjectIdList} from "@/api/cld/CldPayDetails";
import calendar from "./calendar.vue";

export default {
  dicts: ['cld_project_groups', 'cld_project_post', 'cld_project_duits'],
  components: {
    calendar
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 薪酬管理表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: this.$route.params.projectId,
        year: null,
        month: null,
        isSend: 1
      },
      month: null,
      isViewPayOpen: false,
      currRow: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询薪酬管理列表 */
    getList() {
      getCumulativeSalaryByProjectIdList(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.year = this.parseTime(this.month, '{y}');
      this.queryParams.month = this.parseTime(this.month, '{m}');
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 详情查看
    handleViewDetails(row) {
      this.currRow = row;
      this.isViewPayOpen = true;
    },

    // 计算实发工资
    calculateSalary(row) {
      let money = row.basicSalary + row.basedSalary + row.overtimeSalary + row.welfareSalary + row.awardSalary + row.insuranceSalary + row.clothesSalary +
        row.fineSalary + row.workSalary;
      return this.toMoney(money);
    },
  }
};
</script>
<style scoped>
.payTitle {
  text-align: center;
}

.payValueClick {
  text-align: center;
  font-size: 32px;
  cursor: pointer;
  color: #4d00ff;
}

.slant-text {
  position: relative;
  left: 245px;
  top: -80px;

}
</style>
